<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="include/peizhi.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="${ctx}">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
        
        <title>后台管理中心</title> 
		<link rel="stylesheet" href="${ctx}/css/pintuer.css" /> 
		<link rel="stylesheet" href="${ctx}/css/admin.css" /> 
        <script type="text/javascript" src="${ctx}/js/jquery-1.9.1.min.js"></script>
        <script type="text/javascript" src="${ctx}/js/pagehoutai.js"></script>
    </head>
  	<body style="background-color:#f2f9fd;"> 
	  <jsp:include page="include/header.jsp" flush="true"/>
  <div class="admin"> 
  	<div class="panel admin-panel">
	  <div class="panel-head"><strong class="icon-reorder"> 内容列表</strong></div>
	  <div class="padding border-bottom">  
	  <button type="button" class="button border-yellow" onclick="window.location.href='/ht/code/addcode'"><span class="icon-plus-square-o"></span> 添加内容</button>
	   &nbsp;&nbsp;&nbsp;<input type="text" placeholder="行业名称或者行业编码" class="border border-yellow" id="keyhangye" value="" style="width: 10%;height: 5%" /><button onclick="keyhangye()" type="button" class="button border-yellow"> 搜索</button>
	  </div>
	  <table id='pagehtml' class="table table-hover text-center">
	    
	  </table>
	</div>
	<form id="pageForm" action="${ctx}/ht/code/getlist">
		<input type="hidden" name="pageNo" id="pageNo" value="0" /> 
		<input type="hidden" name="pageSize" id="pageSize" value="10" /> 
		<input type="hidden" name="productName" id="productNameid" /> 
		
		<input id='lastPage' type="hidden">
	</form>
	<script type="text/javascript">
	</script>
   <!-- <iframe scrolling="auto" rameborder="0" src="info.jsp" name="right" width="100%" height="100%"></iframe>  -->
  </div> 
 </body>
 <script type="text/javascript">
	page(1,$("#pageSize").val());
	var listhead='<tr>'+
	      '<th width="33%">行业名称</th>'+
	      '<th width="33%">行业编码</th>'+
	      '<th width="33%">操作</th>'+
	    	'</tr>';
	var listhtml = "<tr id={3}del>";
		  listhtml = listhtml + "<td>{0}</td>";
	      listhtml = listhtml + "<td>{1}</td>";     
	       listhtml = listhtml + "<td><div class='button-group'>";
	      listhtml = listhtml + "<a class='button border-red' href='javascript:void(0)' onclick='del({2})'><span class='icon-trash-o'></span> 删除</a>";
	      var listhtml1 =  "<button onclick='redian({4},{5})' id='redian{6}' class='button border-red'> 设置热点</button>";
		var listhtml3 =  "<button onclick='quxiaoredian({4},{5})' id='redian{6}' class='button border-red'> 取消热点</button>";
		var listhtml2 = "</div></td></tr>";
	     
	function pageAppend(data){
		if (data.redian=="1"){
			return (listhtml+listhtml3+listhtml2).replace('{0}',data.productName)
			.replace('{1}',data.productCode)
			.replace('{2}',data.id)
			.replace('{3}',data.id)
			.replace('{4}',data.id)
			.replace('{5}',data.redian)
			.replace('{6}',data.id);
		}else{
			return (listhtml+listhtml1+listhtml2).replace('{0}',data.productName)
			.replace('{1}',data.productCode)
			.replace('{2}',data.id)
			.replace('{3}',data.id)
			.replace('{4}',data.id)
			.replace('{5}',data.redian)
			.replace('{6}',data.id);
		}
	}
	function pageGo(size){
		var last = $("#last").val();
		if(last!=''){
			page(last,size);
		}else{
			alert("选页框不可为空");
		}
		
	}
	//删除
	function del(id){
		if(confirm("您确定要删除吗?")){
			alert("是否删除","deleteAdv("+id+")");
		}
	};
	function deleteAdv(id){
		doOk();
		if(id!='' && id != null){
				$.ajax({
					url:"${ctx}/ht/code/delectCode",
					type:"post",
					data:"id="+id,
					success:function(data){
						if(data=='1'){
							$("#productNameid").val($("#keyhangye").val());
							page($("#pageNo").val(),$("#pageSize").val());
							$("#productNameid").val("");
							/* alert("删除成功");
							$("#"+id+"del").hide(); */
							/* var a = $("#pageNo").val();
							var b = $("#pageSize").val();
							page(parseInt(a)-1,b); */
						}else{
							alert("删除异常，请刷新页面重新删除");
						}
					}
				});
		}else{
			alert("删除异常，请刷新页面重新删除");
		}
		
	}
	function keyhangye(){
		$("#productNameid").val($("#keyhangye").val());
		page(1,$("#pageSize").val());
		$("#productNameid").val("");
	}
	function redian(id,redian){
		$.ajax({
			url:"${ctx}/ht/code/updateredian",
			type:"post",
			data:"id="+id+"&redian="+redian,
			success:function(data){
				if(data=='1'){
					$("#productNameid").val($("#keyhangye").val());
					page($("#pageNo").val(),$("#pageSize").val());
					$("#productNameid").val("");
					//$("#redian"+id).text("取消热点");
					//$("#redian"+id).attr("onclick","quxiaoredian("+id+")");
				}else{
					alert("设置异常，请刷新页面重新设置");
				}
			}
		});	
	}
	function quxiaoredian(id,redian){
		$.ajax({
			url:"${ctx}/ht/code/updateredian",
			type:"post",
			data:"id="+id+"&redian="+redian,
			success:function(data){
				if(data=='1'){
					$("#productNameid").val($("#keyhangye").val());
					page($("#pageNo").val(),$("#pageSize").val());
					$("#productNameid").val("");
					/* $("#redian"+id).text("设置热点");
					$("#redian"+id).attr("onclick","redian("+id+")"); */
				}else{
					alert("设置异常，请刷新页面重新设置");
				}
			}
		});
	}
</script>
</html>